import { NextRequest, NextResponse } from 'next/server';
import { SD_BASE_URL } from '@/lib/config';

export async function GET(request: NextRequest) {
  try {
    // 转发请求到目标API获取upscalers数据
    const response = await fetch(`${SD_BASE_URL}/sdapi/v1/upscalers`, {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
      }
    });

    // 检查响应状态
    if (!response.ok) {
      const detail = await response.text();
      return NextResponse.json(
        { error: 'Request error', detail, status: response.status },
        { status: response.status }
      );
    }

    // 返回目标API的响应
    const data = await response.json();
    return NextResponse.json(data);

  } catch (error: any) {
    // 处理和返回错误
    return NextResponse.json(
      { 
        error: 'Internal Server Error', 
        detail: error.message || 'Unknown error occurred' 
      },
      { status: 500 }
    );
  }
}